package com.szxw.BaiduAi.controller;

import com.szxw.BaiduAi.service.OcrService;
import com.szxw.BaiduAi.utils.FileUtils;
import com.szxw.BaiduAi.utils.MethodUtils;
import org.json.JSONObject;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: 苏执小威
 * @Email:1410511702@qq.com
 * @Desc:
 * @Date: 2022/9/24 17:14
 */
@WebServlet("/ocr")
public class OcrController extends BaiDuController{

    private OcrService service = new OcrService();



    /**
     * 该方法用于实现通用文字识别
     * @param req
     * @param resp
     * @throws IOException
     */
    public void imageOcr(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        //获取参数
        byte[] image = FileUtils.getFileDataByRequest(req);
        //调用接口进行地址识别并得到结果
        JSONObject address = service.basicAccurateGeneral(image);
        //将结果响应到前端
        MethodUtils.close(resp,address);

    }
    /**
     * 该方法用于实现银行卡识别
     * @param req
     * @param resp
     * @throws IOException
     */
    public void bankcard(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        //获取参数
        byte[] image = FileUtils.getFileDataByRequest(req);
        //调用接口进行地址识别并得到结果
        JSONObject address = service.bankcard(image);
        //将结果响应到前端
        MethodUtils.close(resp,address);

    }


}
